package com.zjw.demo.vertx.starter.template.service;

import com.zjw.demo.vertx.starter.annotation.core.Service;
import com.zjw.demo.vertx.starter.config.ApplicationConfig;
import com.zjw.demo.vertx.starter.service.redis.AbstractRedisService;
import io.vertx.core.Vertx;
import io.vertx.redis.client.Redis;
import io.vertx.redis.client.RedisOptions;

@Service
public class RedisService extends AbstractRedisService {

  private static final String TAG = "RedisService";

  @Override
  public void onStart(Vertx vertx) {
    super.onStart(vertx);
  }

  @Override
  protected String[] requireConnectString() {
    return new String[]{ApplicationConfig.getString("redis.connect")};
  }

  @Override
  protected void onConnectBefore(RedisOptions options) {
    options.setMaxPoolSize(5);
    options.setMaxPoolWaiting(16);
  }

  @Override
  protected void onConnectSuccess(Redis client) {
//    client.send(Request.cmd(Command.PUBLISH).arg("chan1").arg("hello world")).onSuccess(r -> {
//    });
//    client.send(Request.cmd(Command.SUBSCRIBE).arg("chan1")).onSuccess(r -> {
//    });
  }

  @Override
  protected void onConnectFailed(Throwable throwable) {

  }
}
